/**
 * 检查输入的表单信息
 * @constructor
 */
function CheckInfo() {
    const event = window.event;
    let from = document.forms[0];
    if (from.username.value != null && from.password != null) {
        // 通过 --submit
        submitForm();
    }
};

function submitForm() {
    let name = $("#loginFrom").username.value;
    const password = $("#loginFrom").password.value;
    //密码，用户名校验，后面做
    loginFrom.submit();
}

function check() {
    const form = document.querySelector('#LoginFrom');
    const formData = new FormData(form);
    // 获取表单数据中的 name 和 age 字段
    //     const name = formData.get('name');
    //     const pass = formData.get('pass');
    let name = document.getElementById("name").value;  //读取表单数据，创建变量
    let pass = document.getElementById("pass").value;
    let phone = document.getElementById("phone").value;
    let dto = {
        id: "",
        username: name,
        password: pass,
        phone: phone,
        update_person: name,
        login_time: new Date(),
        exit_time: "",
        update_time: ""
    }
    //1.是否已经注册
    // let res = checkRegister(dto);
    window.document.f.action = "Dynamic.js";
    //2.未注册，首次登录记录到表中  flag=0
    if (res.result === 0) {
        var b = confirm("用户未注册，是否注册");
        if (b) {
            const res = login(dto);
            if (res.code === 200) {
                alert("登录成功！");
                window.document.f.action = "Dynamic.js";  //此处设置登录后跳转页面
                // 将表单数据提交到服务器,并将表单数据提交到跳转的页面
                window.document.f.submit();
            } else {
                alert("密码错误，禁止登录!");
            }
        } else {
            alert("用户未注册，禁止登录!");
        }
    } else {
        alert("用户名或密码错误！");
    }

}

/**
 * logindto
 */

function checkRegister() {
    let res = '';
    $.ajax({
        type: "post",
        url: "/admin/register",
        data: {"logindto": dto},
        dataType: 'json',
        async: false,
        success: function (data) {
            if (result !== null) {
                res = data;
            } else {
                alert("提示:系统繁忙!")
            }
        }
    });
    return res;
}

function login(dto) {
    let res = '';
    $.ajax({
        type: "post",
        url: "/admin/login",
        data: {"logindto": dto},
        dataType: 'json',
        async: false,
        success: function (data) {
            if (result !== null) {
                res = data;
            } else {
                alert("提示:系统繁忙!")
            }
        }
    });
    return res;
};